package cn.changeforyou.web.cloud.auth.service.impl;

import cn.changeforyou.web.cloud.rpc.service.auth.enums.OpenLevel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.changeforyou.web.cloud.auth.entity.SourceInfo;
import cn.changeforyou.web.cloud.auth.service.SourceInfoService;
import cn.changeforyou.web.cloud.auth.mapper.SourceInfoMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class SourceInfoServiceImpl extends ServiceImpl<SourceInfoMapper, SourceInfo>
        implements SourceInfoService {

    @Override
    public List<SourceInfo> getOpenAndHalfOpenSources() {
        List<SourceInfo> list = this.list();
        List<SourceInfo> result = new ArrayList<>();
        if (list.isEmpty()) {
            return result;
        }
        for (SourceInfo sourceInfo : list) {
            OpenLevel openLevel = sourceInfo.getOpenLevel();
            if(openLevel == OpenLevel.halfOpen || openLevel == OpenLevel.open) {
                result.add(sourceInfo);
            }
        }
        return result;
    }
}




